/*        This file is part of P5ovray.
        
        P5ovray is free software: you can redistribute it and/or modify
        it under the terms of the GNU Lesser General Public License as 
        published by the Free Software Foundation, either version 3 of 
        the License, or (at your option) any later version.
        
        P5ovray is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU Lesser General Public License for more details.
        
        You should have received a copy of the GNU Lesser General Public
        License along with P5ovray.  If not, see <http://www.gnu.org/licenses/>.
*/

package zombie.povray;

import java.util.ArrayList;

import zombie.P5ovray;

import zombie.povray.P5ovWriter;
import zombie.povray.P5ovObject;

public class P5ovScene {
	
	P5ovWriter pw;
	ArrayList<P5ovObject> objects;
	P5ovray parent;
	
	public float ambientR = 1;
	public float ambientG = 1;
	public float ambientB = 1;
	
	public P5ovScene( P5ovray _parent )
	{
		pw = new P5ovWriter( _parent.getApplet() );
		objects = new ArrayList<P5ovObject>();
		parent = _parent;
	}
	
	public void writeHeader()
	{
		pw.println("//\tThis file was generated by the P5ovRay plugin for Processing.org\n//\tThe plugin was written by Andy Best ( http://andybest.net )\n//\tFor more information on this plugin, go to http://p5ovray.andybest.net\n//\tFor more information about processing, go to http://processing.org\n");
		pw.println("#version 3.6;");
	}
	
	private void writeGlobals()
	{
		pw.println("global_settings {");
		pw.println("ambient_light rgb<" + ambientR + ", " + ambientG + ", " + ambientG + ">");
		pw.println("}\n");
	}
	
	private void writeCamera(){
		pw.println("camera {");
		pw.println("\tlocation <" + parent.povCamera.x +", " + parent.povCamera.y + ", " + parent.povCamera.z + ">");
		pw.println("\tlook_at <" + parent.povCamera.lookatX +", " + parent.povCamera.lookatY + ", " + parent.povCamera.lookatZ + ">");
		pw.println("\tup <" + parent.povCamera.upX +", " + parent.povCamera.upY + ", " + parent.povCamera.upZ + ">");
		pw.println("\tright <" + (parent.povCamera.width / parent.povCamera.height) +", " + 0.0 + ", " + 0.0 + ">");
		pw.println("}\n");
	}
	
	public void addObject(P5ovObject _object)
	{
		objects.add(_object);
	}
	
	private void printObjects()
	{
		for(int i = 0; i < objects.size(); i++){
			P5ovObject _object = objects.get(i);
			pw.println(_object.getString() );
		}
		pw.flush();
	}
	
	public void writeScene()
	{
		writeHeader();
		writeGlobals();
		writeCamera();
		printObjects();
	}
	
	
}
